
define(function (require, exports) {
    exports.ready = function (hashCode, data, cite) {
        yufp.custom.vue({
            el: cite.el,
            data: function () {
                var _this = this;
                return {
                    setIntervalId: "",
                    currentDateTime: "",
                    intervalSelection: 60000,
                    resourceNodeList: [],
                    refreshIntervalOptions: [
                        { key: 864000000, label: '不自动刷新' },
                        { key: 10000, label: '10秒' },
                        { key: 20000, label: '20秒' },
                        { key: 30000, label: '30秒' }, 
                        { key: 60000, label: '60秒' }
                    ]
                };
            },
            mounted() {
                var _this = this;
                _this.queryResourceInfo();
                _this.scheduletrigger();
            },
            watch: {
                intervalSelection(val) {
                    var _this = this;
                    clearInterval(_this.setIntervalId);
                    _this.setIntervalId = setInterval(() => {
                        _this.queryResourceInfo(false);
                    }, _this.intervalSelection);
                }
            },
            methods: {
                scheduletrigger: function () {
                    var _this = this;
                    _this.setIntervalId = setInterval(() => {
                        _this.queryResourceInfo(false);
                    }, _this.intervalSelection);
                },
                checkOnclick: function (data) {
                    // var customKey = 'custom_' + data.addressIp.replace(/\./g,"");
                    var customKey = 'custom_resource_resourceDetail';
                    var routeId = 'router_' + data.addressIp.replace(/\./g, "");
                    var url = 'pages/use/monitors/resourceMonitor/resourceDetail';

                    if (yufp.router.getRoute(routeId) == null || JSON.stringify(yufp.router.getRoute(routeId)) == "{}") {
                        yufp.router.addRoute(routeId, {
                            html: url + '.html',
                            js: url + '.js'
                        });
                    }
                    if (yufp.frame.getTab(customKey) != null) {
                        yufp.frame.removeTab(customKey);
                    }
                    if (yufp.frame.getTab(customKey) == null)
                        yufp.frame.addTab({
                            id: routeId, // 菜单功能ID（路由ID）
                            key: customKey, // 自定义唯一页签key,请统一使用custom_前缀开头
                            title: '资源详情[' + data.addressIp + ']', // 页签名称
                            data: data// 传递的业务数据，可选配置
                        });
                },
                refreshData: function () {
                    this.queryResourceInfo(true);
                },
                queryResourceInfo: function (flag) {
                    var _this = this;
                    yufp.service.request({
                        url: backend.useService + '/monitor/resources/queryList',
                        method: 'get',
                        data: {},
                        callback: function (code, message, response) {
                            if (code == 0) {
                                _this.currentDateTime = response.message;
                            }
                            if (response && response.data) {
                                if (response.data.length > 0) {
                                    _this.resourceNodeList.splice(0);
                                    for (let i = 0; i < response.data.length; i++) {
                                        _this.resourceNodeList.push(response.data[i]);
                                    }
                                }
                            }
                            if (flag) {
                                _this.$message("刷新成功");
                            }
                        }
                    });
                },
            }
        });
    };
});